<?php
/**
 * MongoDig
 *
 * @copyright  Copyright (c) 2010 lanyanguang (http://www.lanyg.com)
 * @license    GNU General Public License 2.0
 * @version    $Id$
 */

/** 初始化 */
require_once 'init.php';

//判断是否登录
if(!$user_id = is_login()){
 	header("Location:" . $config['site_url'] . '/login.php');
	exit;
}

//页面提交处理
if(isset($_POST['Submit'])){
	$url = trim($_POST['url']);
	$title = trim($_POST['title']);
	$description = trim($_POST['description']);
	$cat_id = trim($_POST['cat_id']);
	if(!empty($url) && !empty($title)&& !empty($description)&& !empty($cat_id)){
		include_logic('topic');
		topic_insert(array(
		'url'=>$url,
		'title'=>$title,
		'description'=>$description,
		'cat_id'=>$cat_id,
		'user_id'=>"$user_id",
		'entry_time'=>time(),
		'comment'=>array(),
		'score'=>0
		));
		header('Location:'.$config['site_url'].'/index.php');
		exit;
	}
}

$_GLOBAL['page_title'] = 'Add Topic';

//载入登录页面
include_template('add_topic');